<?php

namespace App\Admin\Controllers;

use App\Models\OrderInfoModel;
use App\Models\OrderModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrderController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\Models\OrderModel';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new OrderModel());

        $grid->column('id', __('Id'));
       // $grid->column('goods_id', __('Goods id'));
        $grid->column('goods_name','报名线路名称');
        //$grid->column('user_id', __('User id'));
        $grid->column('originator_name','发起人姓名');
        $grid->column('head_img','头像')->image('', 80, 80);
        $grid->column('enrolment_number','参团人数');
        //$grid->column('country_id', __('Country id'));
        $grid->column('country','国家');
        //$grid->column('line_id', __('Line id'));
        $grid->column('line','线路');
        //$grid->column('city_id', __('City id'));
        $grid->column('city','城市');
        $grid->column('start_time','报名开始时间');
        $grid->column('end_time','报名结束时间');
        $grid->column('price','价格');
        //$grid->column('favorable_price','');
       // $grid->column('Integral_price', __('Integral price'));
        $grid->column('pay_status','支付状态')->using(['1' =>'付款','2' =>'未支付','3'=>'已完成','4'=>'已取消','5'=>'已经开始'])->label([
            1 => 'success',
            2 => 'warning',
            3 => 'success',
            4 => 'warning',
            5 => 'success',
        ]);

       // $grid->column('store_id', __('Store id'));
        $grid->column('store_name','门店名称');
        $grid->column('price_info','价格说明');
        $grid->column('remarks','备注');

        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));


        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(OrderModel::findOrFail($id));

        $show->field('id', __('Id'));
       // $show->field('goods_id', __('Goods id'));
        $show->field('goods_name','线路名称');
        //$show->field('user_id', __('User id'));
        $show->field('originator_name','发起人姓名');
        $show->field('head_img','头像')->image();
        $show->field('enrolment_number','参团人数');
        //$show->field('country_id', __('Country id'));
        $show->field('country','国家');
        //$show->field('line_id', __('Line id'));
        $show->field('line','线路类型');
        //$show->field('city_id', __('City id'));
        $show->field('city','城市');
        $show->field('start_time','报名开始时间');
        $show->field('end_time','停止报名时间');
        $show->field('price','价格');
    /*    $show->field('
        favorable_price', __('
        favorable price'));
        $show->field('Integral_price', __('Integral price'));*/

        $show->field('store_name','报名管理');
        $show->field('price_info','价格说明');
        $show->field('remarks','备注');

        $show->pay_status('订单状态')->using(['1' =>'付款','2' =>'未支付','3'=>'已完成','4'=>'已取消','5'=>'已经开始']);

        //$order_info = new Grid(new OrderInfoModel());
        $show->order_info('订单详情/报名团队', function ($order_info) {

            $order_info->resource('/admin/order-info-models');
            //var_dump($order_info);die;

            $order_info->id();
            $order_info->real_name('姓名');
            $order_info->id_card('身份证');
            $order_info->passport('护照');
           // $order_info->passport();

            $order_info->disableCreateButton();
            $order_info->disableFilter();
            $order_info->disableExport();
            $order_info->actions(function ($actions) {
                // $actions->disableDelete();
                $actions->disableEdit();
            });
         /*   $comments->content()->limit(10);
            $comments->created_at();
            $comments->updated_at();

            $comments->filter(function ($filter) {
                $filter->like('content');
            });*/
        });

        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
       // $show->field('store_id', __('Store id'));


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new OrderModel());

       /* $form->number('goods_id', __('Goods id'));
        $form->text('goods_name', __('Goods name'));
        $form->number('user_id', __('User id'));
        $form->text('originator_name', __('Originator name'));
        $form->text('head_img', __('Head img'));
        $form->number('enrolment_number', __('Enrolment number'));
        $form->number('country_id', __('Country id'));
        $form->text('country', __('Country'));
        $form->number('line_id', __('Line id'));
        $form->text('line', __('Line'));
        $form->number('city_id', __('City id'));
        $form->text('city', __('City'));
        $form->datetime('start_time', __('Start time'))->default(date('Y-m-d H:i:s'));
        $form->datetime('end_time', __('End time'))->default(date('Y-m-d H:i:s'));
        $form->decimal('price', __('Price'))->default(0.00);
        $form->decimal('
        favorable_price', __('
        favorable price'));
        $form->decimal('Integral_price', __('Integral price'));*/
        $form->radio('pay_status','更改订单状态')
            ->options([1 => '付款', 2=> '未付款',3=> '已完成',4=> '已取消',5=>'已经开始'])
            ->default(2);

        /*   $form->number('store_id', __('Store id'));
           $form->text('store_name', __('Store name'));
           $form->textarea('price_info', __('Price info'));
           $form->textarea('remarks', __('Remarks'));*/

        return $form;
    }


}
